package com.itheima.gongjulei;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;

/*
计数闭锁
 */
public class Demo01 {

    public static void main(String[] args) {









        CountDownLatch countDownLatch = new CountDownLatch(8);

        Caipan caipan = new Caipan(countDownLatch);
        Thread caipanT = new Thread(caipan);
        for (int i = 0; i < 8; i++) {

            Yundongyuan y = new Yundongyuan(countDownLatch);
            Thread t = new Thread(y);
            t.setName(i+"号");
            t.start();
        }
        caipanT.start();

    }


}
class Caipan implements Runnable{
  private CountDownLatch countDownLatch ;

    public Caipan(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //等人到齐 预备 射
        System.out.println("预备跑");

    }
}
class Yundongyuan implements Runnable{
    private CountDownLatch countDownLatch ;

    public Yundongyuan(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {

        //就绪准备跑
        String name = Thread.currentThread().getName();

        System.out.println(name+"选手以就绪");
        countDownLatch.countDown();
    }
}